package com.zhs.smartmall.member.service.impl;


import com.zhs.smartmall.member.model.UmsMember;
import com.zhs.smartmall.member.dao.UmsMemberDao;
import com.zhs.smartmall.member.service.IUmsMemberService;
import com.zhs.smartmall.member.dto.UmsMemberDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class UmsMemberServiceImpl extends ServiceImpl< UmsMemberDao, UmsMember> implements IUmsMemberService {

    @Resource
    private UmsMemberDao umsMemberDao;

    @Override
    @Transactional
    public R addOrUpdate(UmsMemberDto umsMemberDto) {
        if (BeanUtil.isEmpty(umsMemberDto)) throw new ServiceException("数据不能为空");
        UmsMember umsMember = new UmsMember();
        BeanUtil.copyProperties(umsMemberDto,umsMember);
        if (umsMemberDto.getId() == null){
            umsMemberDao.insert(umsMember);
            return R.ok("数据插入成功");
        }else {
            umsMemberDao.updateById(umsMember);
            return R.ok("数据更新成功");
        }
    }
}